package com.mrx.pvzcommunity.config;

import com.github.xiaoymin.knife4j.spring.extension.OpenApiExtensionResolver;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

@Configuration
@RequiredArgsConstructor
public class Knife4jConfiguration {

    private final OpenApiExtensionResolver openApiExtensionResolver;

    @Bean
    public Docket defaultApi2(
            @Value("${knife4j.api.title}") String title,
            @Value("${knife4j.api.description}") String description,
            @Value("${knife4j.api.version}") String version
    ) {
        return new Docket(DocumentationType.OAS_30)
                .apiInfo(new ApiInfoBuilder()
                        .title(title)
                        .description(description)
                        .version(version)
                        .license("Apache 2.0")
                        .license("https://springdoc.org")
                        .contact(new Contact("Mr.X", "http://localhost", "1725338233@qq.com"))
                        .build()
                )
                .groupName("PVZ 社区 API")
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.mrx.pvzcommunity.controller"))
                .paths(PathSelectors.any())
                .build()
                .extensions(openApiExtensionResolver.buildSettingExtensions());
    }
}